﻿using System;
using NUnit.Framework;

namespace PropertyExpression.TypedSqlBuilder.Test
{
    [TestFixture]
    public class SqlTest
    {
        [Test]
        public void Test4()
        {
            var query = NewMethod1("", "", DateTime.Now, DateTime.Now);
            Console.WriteLine(query);
        }

        private static IFrom<SalesOrderHeaderProjection> NewMethod1(
            string productName, string contactFirstName,
            DateTime startOrderDate, DateTime endOrderDate)
        {
            return
                Query.From(Schema.SalesOrderHeaders, salesOrderHeader =>
                    Query.InnerJoin(Schema.SalesOrderDetails, salesOrderDetail => Query.To(
                        salesOrderHeader.SalesOrderID().Equal(salesOrderDetail.SalesOrderID()),
                    Query.InnerJoin(Schema.SpecialOfferProducts, specialOfferProduct => Query.To(
                        salesOrderDetail.SpecialOfferID().Equal(specialOfferProduct.SpecialOfferID())
                        .And(salesOrderDetail.ProductID().Equal(specialOfferProduct.ProductID())),
                    Query.InnerJoin(Schema.SpecialOffers, specialOffer => Query.To(
                        specialOfferProduct.SpecialOfferID().Equal(specialOffer.SpecialOfferID()),
                    Query.InnerJoin(Schema.Products, product => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Products, product2 => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Products, product3 => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Products, product4 => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Products, product5 => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Products, product6 => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Products, product7 => Query.To(
                        specialOfferProduct.ProductID().Equal(product.ProductID()),
                    Query.InnerJoin(Schema.Individuals, individual => Query.To(
                        salesOrderHeader.CustomerID().Equal(individual.CustomerID()),
                    Query.InnerJoin2(Schema.Contacts, contact => Query.To2(
                        individual.ContactID().Equal(contact.ContactID()),
                Query.Where(
                    product.Name().Like(productName.Const())
                    .And(
                    contact.FirstName().Like(contactFirstName.Const()))
                    .And(
                    salesOrderHeader.OrderDate().Between(startOrderDate.Const(), endOrderDate.Const()))
                    ),
                Query.Select<SalesOrderHeaderProjection>()
                    .OrderDate(salesOrderHeader.OrderDate())
                    .ProductName(product.Name())
                    .ContactFirstName(contact.FirstName())
                )))))))))))))))))))))))));
        }
    }
}
